{% extends 'template.html' %}
{% load staticfiles %}

{% block username %}
    {{ request.user.username }}
{% endblock %}

{% block content %}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">salt 命令执行记录</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="btn-group">
                            <a href="javascript:" onclick="self.location=document.referrer;" class="btn btn-success">返回</a>
                        </div>
                    </div>
                    <div class="panel-body">
                        {% if history %}
                            <table id="mytable" width="100%" cellspacing="0"
                                   class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th>执行时间</th>
                                    <th>执行人</th>
                                    <th>执行命令</th>
                                    <th>执行结果</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for h in history %}
                                    <tr>
                                        <td>{{ h.execute_time|date:"Y-m-d H:i:s" }}</td>
                                        <td>{{ h.execute_user.username }}</td>
                                        <td>{{ h.command }}</td>
                                        <td>
                                            <button class="btn btn-sm btn-info" onclick="view_detail({{ h.id }})">
                                                点击查看详情
                                            </button>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p>还没有执行记录！</p>
                        {% endif %}
                    </div>
                </div>
            </div>


            <!-- Execute Modal Detail-->
            <div class="modal fade" id="Modal-execute" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" style="width:1000px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">执行详情</h4>
                        </div>
                        <form>
                            <div class="modal-body" style="height:750px;overflow:auto;">
                                <div readonly style="background-color: #333;height:600px;width:100%;overflow:auto" id="execute_result"></div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>

            <div id="is_superuser" data-is-superuser="{{ is_superuser }}"></div>

        </div>
    </div>
{% endblock %}
{% block bodyjs %}
    {% verbatim %}
    <script id="tpl" type="text/x-handlebars-template">
        {{#each func}}
        <button type="button" class="btn btn-sm btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>
        {{/each}}
    </script>
    {% endverbatim %}
    <script src="/static/js/handlebars-v3.0.1.js"></script>
    <script src="/static/js/jquery.dataTables.min.js"></script>
    <script src="/static/js/dataTables.colVis.js"></script>
    <script src="/static/js/salt_command_history.js?v=20190610001"></script>
{% endblock %}
{% block css %}
    <link href="/static/css/jquery.dataTables.css" rel="stylesheet" type="text/css">
    <link href="/static/css/dataTables.colVis.css" rel="stylesheet" type="text/css">
    <link href="/static/css/system_cron_list.css" rel="stylesheet" type="text/css">
{% endblock %}
